#include <cstdio>
#include <cstdlib>
#include <queue>
#include <tuple>
constexpr int MaxN = 1e6 + 5;
int n, m;
int *p[MaxN];
char *s[MaxN];
bool *vis[MaxN];
bool *cover[MaxN];
std::priority_queue<std::tuple<int, int, int>> queue;
void push(int x, int y)
{
    if (!(1 <= x && x <= n && 1 <= y && y <= m) || s[x][y] == '.')
    {
        return;
    }
    queue.push({p[x][y], x, y});
}
void calc(int x, int y)
{
    if (!(1 <= x && x <= n && 1 <= y && y <= m) || s[x][y] == '.')
    {
        return;
    }
    p[x][y] = (s[x - 1][y] != '#' || vis[x - 1][y] ? 1 : 0) + (s[x + 1][y] != '#' || vis[x + 1][y] ? 1 : 0) +
              (s[x][y - 1] != '#' || vis[x][y - 1] ? 1 : 0) + (s[x][y + 1] != '#' || vis[x][y + 1] ? 1 : 0);
}
void take(int x, int y)
{
    // fprintf(stderr, "Cover (%d, %d)\n", x, y);
    if (cover[x][y])
    {
        return;
    }
    cover[x][y] = true;
    vis[x][y] = true;
    vis[x - 1][y] = true;
    vis[x + 1][y] = true;
    vis[x][y - 1] = true;
    vis[x][y + 1] = true;
    for (int sx = -2; sx <= 2; sx++)
    {
        for (int sy = -2; sy <= 2; sy++)
        {
            if (abs(sx) + abs(sy) != 2)
            {
                continue;
            }
            calc(x + sx, y + sy);
            push(x + sx, y + sy);
        }
    }
}
int main()
{
    freopen("indian.in", "r", stdin);
    freopen("indian.out", "w", stdout);
    scanf("%d%d", &n, &m);
    for (int i = 0; i <= n + 1; i++)
    {
        p[i] = new int[m + 5];
        s[i] = new char[m + 5];
        vis[i] = new bool[m + 5];
        cover[i] = new bool[m + 5];
        for (int j = 0; j < m + 5; j++)
        {
            p[i][j] = 0;
            s[i][j] = 0;
            vis[i][j] = false;
            cover[i][j] = false;
        }
    }
    for (int i = 1; i <= n; i++)
    {
        scanf("%s", s[i] + 1);
    }
    for (int i = 1; i <= n; i++)
    {
        for (int j = 1; j <= m; j++)
        {
            if (s[i][j] != '#')
            {
                continue;
            }
            calc(i, j);
            push(i, j);
        }
    }
    for (; !queue.empty();)
    {
        const auto [d, x, y] = queue.top();
        queue.pop();
        if (p[x][y] != d || cover[x][y] || vis[x][y])
        {
            continue;
        }
        if (s[x - 1][y] == '#' && !vis[x - 1][y])
        {
            take(x - 1, y);
        }
        else if (s[x + 1][y] == '#' && !vis[x + 1][y])
        {
            take(x + 1, y);
        }
        else if (s[x][y - 1] == '#' && !vis[x][y - 1])
        {
            take(x, y - 1);
        }
        else if (s[x][y + 1] == '#' && !vis[x][y + 1])
        {
            take(x, y + 1);
        }
        else
        {
            take(x, y);
        }
    }
    for (int i = 1; i <= n; i++)
    {
        for (int j = 1; j <= m; j++)
        {
            if (s[i][j] == '.')
            {
                printf(".");
            }
            else
            {
                printf("%c", cover[i][j] ? '1' : '0');
            }
        }
        printf("\n");
    }
    return 0;
}